<template>
  <div id="logout">
    <div class="content head">
      <div class="l_con">头像</div>
      <div class="r_con">
        <div class="headImg"></div>
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content mt">
      <div class="l_con">昵称</div>
      <div class="r_con">
        <input type="text" v-model="username" />
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content">
      <div class="l_con">手机号码</div>
      <div class="r_con">
        <input type="text" v-model="phonenumber" />
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content">
      <div class="l_con">地址管理</div>
      <div class="r_con">
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content mt" @click="updatePsw">
      <div class="l_con">登录密码</div>
      <div class="r_con">
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content">
      <div class="l_con">支付密码</div>
      <div class="r_con">
        <van-icon name="arrow" />
      </div>
    </div>
    <div class="content logoutBtn" @click="logout">
      <p>退出登录</p>
    </div>
  </div>
</template>

<script>
import Api from "../Api";

export default {
  data: function() {
    return {
      phonenumber: this.$store.state.common.user.phone,
      username: ""
    };
  },
  methods: {
    //退出
    logout() {
      this.$store.commit("logout");
      this.phonenumber = "";
      this.username = "";
      this.$router.push("/reg");
    },
    updatePsw() {
      this.$router.push("/updatePsw");
    }
  },

  async created() {
    window.console.log(this.phonenumber);
    if (this.phonenumber) {
      await Api.my
        .get("/users/profile", {
          phonenumber: this.phonenumber
        })
        .then(res => {
          if (res.data.data[0].username) {
            this.username = res.data.data[0].username;
          }
        });
    }
  }
};
</script>

<style lang="scss" scoped>
#logout {
  background-color: #f6f6f6;
  padding-top: 0.266667rem;
  font-size: 0.4rem;

  .content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 0.32rem;
    background-color: #fff;
    height: 1.466667rem;
    line-height: 1.466667rem;
    border-bottom: 1px solid #f6f6f6;
    .r_con {
      display: flex;
      align-items: center;
      .van-icon {
        margin-left: 0.4rem;
      }
      input {
        text-align: right;
      }
    }
  }
  .mt {
    margin-top: 0.266667rem;
  }
  .head {
    height: 2.346667rem;
    line-height: 2.346667rem;
    .headImg {
      width: 1.2rem;
      height: 1.2rem;
      border-radius: 50%;
      overflow: hidden;
      background: url(http://image.360hwj.com/mall/J2zAA1mZH6-AQ-G_AAAEadr9AHg271.png)
        no-repeat center center;
      background-size: 100% 100%;
    }
  }
  .logoutBtn {
    margin-top: 3.733333rem;
    color: #ff5900;
    p {
      text-align: center;
      width: 100%;
    }
  }
}
</style>